| trendTicks {GCDkit} | R Documentation |
Adding a trend with arrow and tick marks to a pre-existing GCDkit plot.
trendTicks(equation=NULL, x, y = NULL,
xmin = par("usr")[1], xmax = par("usr")[2],
tick = abs(par("tcl")), col = "blue", lty = "solid",
lwd = 1, arrow = FALSE, text = "", text.adj = c(1,0.5),
plot=TRUE, autoscale = TRUE)
equation |
character or expression; a valid formula expressed as a function of |
x |
numeric; x values where the ticks are to be drawn. |
y |
numeric; (optional) y values where the ticks are to be drawn. |
xmin |
numeric; beginning of the trend. |
xmax |
numeric; end of the trend. |
tick |
numeric; length of a tick as a fraction of the height of a line of text. |
col |
text or numeric; plotting colour specification. |
lty |
text or numeric; the line type. |
lwd |
numeric; the line width, a positive number, defaulting to 1. |
arrow |
logical; should be also an arrow head shown? |
text |
character; (optional) labels for individual ticks. |
text.adj |
adjustment of the text. See |
plot |
logical; should be the trend plotted? |
autoscale |
logical; should the plot be autosized in order to accommodate the whole trend as well as all data points? |
Using the function curve, the function trendTicks adds to an existing GCDkit plot
a linear or curved trend with tick marks and (optionally) arrow head. If equation is provided,
it is required that the trend is defined as a function of x. Otherwise, a fourth-order polynomial
is fitted to the [x, y] data. If plot = FALSE, no trend is plotted (and only the calculations
are performed).
The slope of the individual tick marks is determined using a numerical derivative of the main function at the respective points.
Returns (invisibly) a list with the following components:
equation |
expression, specified/fitted equation for the trend, |
results |
coordinates of the points from which the ticks are drawn,
if |
x, y |
|
slopes |
slopes of the tick lines, |
ticks |
numeric matrix; |
text.labels |
textual labels to individual ticks; list of parameters to the function |
arrow.head |
numeric matrix, [x,y] coordinates of the arrow head. |
Autoscaling will work only with Figaro compatible plots!
Vojtěch Janoušek, vojtech.janousek@geology.cz
sampleDataset("sazava")
# EXAMPLE 1
# Equation provided, real data, no autoscaling
binary("Ba","Sr",xmin=200,xmax=2000,ymin=10,ymax=650)
figCex(1.5)
equation<-"x/8+200"
x<-seq(2000,500,by=-100)
out<-trendTicks(equation,x=x,xmin=min(x),xmax=max(x),col="darkred",lty="solid",
lwd=2,arrow=TRUE,autoscale=TRUE)
# EXAMPLE 2
# Just the trend, autoscaled, x axis is logarithmic
windows()
plot(1,1,type="n",xlim=c(50,150),ylim=c(50,250),xlab="Rb",ylab="Sr",log="xy")
equation<-"15*x/8+10"
x<-seq(50,120,length=10)
trendTicks(equation,x=x,xmin=min(x),xmax=max(x),col=2,lwd=2,
arrow=FALSE,autoscale=FALSE)
# EXAMPLE 3
# Calculate Rayleigh-type fractionation trend
ff<-seq(1,0.1,-0.1) # F, amount of melt left
x<-80*ff^(1.2-1) # cL for three elements, arbitrary D of 1.2, 2.0 and 1.3
y<-550*ff^(2.0-1)
z<-1000*ff^(1.3-1)
my.trend<-cbind(x,y,z)
colnames(my.trend)<-c("Rb","Sr","Ba")
rownames(my.trend)<-ff
# No equation provided, just [x,y] data are given
# Linear coordinates, autoscaled to accommodate both data and trend
binary("Rb","Sr",log="",xaxs="r",yaxs="r")
out<-trendTicks(equation=NULL,x=x,y=y,xmin=min(x),xmax=max(x),col="red",text=ff)
# Linear coordinates, not autoscaled
binary("Rb","Sr",log="",xaxs="r",yaxs="r")
out<-trendTicks(equation=NULL,x=x,y=y,xmin=min(x),xmax=max(x),col="red",text=ff,
autoscale=FALSE)
# The same, no trend plotting (just calculating for later use)
binary("Rb","Sr",log="",xaxs="r",yaxs="r",xmin=20,xmax=100,ymin=10,ymax=700)
out<-trendTicks(equation=NULL,x=x,y=y,xmin=20,xmax=100,col="red",text=ff,
arrow=TRUE,plot=FALSE)
# Manual overplotting of the trend from the object 'out'
# Points
points(out$results["x",],out$results["y_obs.",],col="red",pch="+",cex=2)
# Trend curve
figRedraw()
.curveMy(out$equation,from=min(out$results["x",],na.rm=TRUE),to=max(out$results["x",],na.rm=TRUE),
col="red",lty="solid",lwd=2)
# Tick marks
segments(out$ticks[,"x1"],out$ticks[,"y1"],out$ticks[,"x2"],out$ticks[,"y2"],col="red",lwd=2)
# Arrow head
lines(out$arrow.head,col="red",lwd=2)
# Textual labels, no rotation
text(out$text.labels$x,out$text.labels$y,out$text.labels$text,pos=3)
# EXAMPLE 4
# Logarithmic coordinates
binary("Rb","Sr",log="x")
trendTicks(equation=NULL,x=x,y=y,xmin=min(x),xmax=max(x),col="red",text=ff,autoscale=TRUE)